const sequelizeService = require('feathers-sequelize')
const SERVICE_NAME = '/test1'

class Test {
  id = 0
  name = ''
}

class TestService {
  private tests: Test[] = []

  setup(app: any, path: string) {
    console.log('setup service: /' + path)
  }

  //GET
  find(params: any, callback: Function) {
    return Promise.resolve(this.tests)
  }

  //GET
  get(id: string, params: any) {
    let result = this.tests.find(item => item.name === id) || {}
    return Promise.resolve(result)
  }

  //POST
  create(data: Test, params: any) {
    let test = new Test()
    test.id = this.tests.length + 1
    test.name = data.name || ''
    this.tests.push(test)

    return Promise.resolve(test)
  }

  update(id: string, data: Test, params: any) {

    return Promise.resolve(data)
  }

  patch(id: string, data: Test, params: any) {

    return Promise.resolve(data)
  }

  remove(id: string, params: any) {
    return Promise.resolve({
      id,
      success: true
    })
  }
}

export = function () {
    this.use(`/${SERVICE_NAME}`, new TestService())
    const service = this.service(SERVICE_NAME)
    
    service.create({
      name: 'test1',
    })
}
